﻿/*
-----------------------------------------------------------------------------
This source file is part of Cell Cloud.

Copyright (c) 2009-2012 Cell Cloud Team - cellcloudproject@gmail.com

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
-----------------------------------------------------------------------------
*/

#ifndef CellPropertyReference_h
#define CellPropertyReference_h

#include "CellPrerequisites.h"

namespace cell
{

/**
*/
template <typename T>
class _CellExport PropertyReference : public GeneralAlloc
{
public:
	/**
	*/
	PropertyReference(void)
	{
	}

	/**
	*/
	PropertyReference(const String& key, T value)
		: mKey(key)
		, mValue(value)
	{
	}

	/**
	*/
	PropertyReference(const PropertyReference& other)
		: mKey(other.mKey)
		, mValue(other.mValue)
	{
	}

	/**
	*/
	virtual ~PropertyReference(void)
	{
	}

public:
	/**
	*/
	PropertyReference& operator=(const PropertyReference& r)
	{
		mKey = r.mKey;
		mValue = r.mValue;
		return *this;
	}

	/**
	*/
	const String& getKey(void) const
	{
		return mKey;
	}

	/**
	*/
	T getValue(void) const
	{
		return mValue;
	}

private:
	String mKey;
	T mValue;
};



/**
*/
class _CellExport AbstractProperty : public GeneAlloc
{
public:
	/**
	*/
	AbstractProperty(void);

	/**
	*/
	virtual ~AbstractProperty(void);

public:
	/**
	*/
	virtual const String& getKey(void) const = 0;

	/**
	*/
	virtual void copy(AbstractProperty* dest) const = 0;
};



/**
*/
class _CellExport BoolProperty : public AbstractProperty
{
public:
	/**
	*/
	BoolProperty(void);

	/**
	*/
	BoolProperty(const String& key, bool value);

	/**
	*/
	BoolProperty(const BoolProperty& other);

	/**
	*/
	virtual ~BoolProperty(void);

public:
	/**
	*/
	BoolProperty& operator=(const BoolProperty& r);

	/**
	*/
	const String& getKey(void) const;

	/**
	*/
	bool getValue(void) const;

	/**
	*/
	void copy(AbstractProperty* dest) const;

private:
	PropertyReference<bool> mReference;
};


/**
*/
class _CellExport IntProperty : public AbstractProperty
{
public:
	/**
	*/
	IntProperty(void);

	/**
	*/
	IntProperty(const String& key, int value);

	/**
	*/
	IntProperty(const IntProperty& other);

	/**
	*/
	virtual ~IntProperty(void);

public:
	/**
	*/
	IntProperty& operator=(const IntProperty& r);

	/**
	*/
	const String& getKey(void) const;

	/**
	*/
	int getValue(void) const;

	/**
	*/
	void copy(AbstractProperty* dest) const;

private:
	PropertyReference<int> mReference;
};


/**
*/
class _CellExport UintProperty : public AbstractProperty
{
public:
	/**
	*/
	UintProperty(void);

	/**
	*/
	UintProperty(const String& key, uint value);

	/**
	*/
	UintProperty(const UintProperty& other);

	/**
	*/
	virtual ~UintProperty(void);

public:
	/**
	*/
	UintProperty& operator=(const UintProperty& r);

	/**
	*/
	const String& getKey(void) const;

	/**
	*/
	uint getValue(void) const;

	/**
	*/
	void copy(AbstractProperty* dest) const;

private:
	PropertyReference<uint> mReference;
};


/**
*/
class _CellExport LongProperty : public AbstractProperty
{
public:
	/**
	*/
	LongProperty(void);

	/**
	*/
	LongProperty(const String& key, long value);

	/**
	*/
	LongProperty(const LongProperty& other);

	/**
	*/
	virtual ~LongProperty(void);

public:
	/**
	*/
	LongProperty& operator=(const LongProperty& r);

	/**
	*/
	const String& getKey(void) const;

	/**
	*/
	long getValue(void) const;

	/**
	*/
	void copy(AbstractProperty* dest) const;

private:
	PropertyReference<long> mReference;
};


/**
*/
class _CellExport UlongProperty : public AbstractProperty
{
public:
	/**
	*/
	UlongProperty(void);

	/**
	*/
	UlongProperty(const String& key, ulong value);

	/**
	*/
	UlongProperty(const UlongProperty& other);

	/**
	*/
	virtual ~UlongProperty(void);

public:
	/**
	*/
	UlongProperty& operator=(const UlongProperty& r);

	/**
	*/
	const String& getKey(void) const;

	/**
	*/
	ulong getValue(void) const;

	/**
	*/
	void copy(AbstractProperty* dest) const;

private:
	PropertyReference<ulong> mReference;
};


/**
*/
class _CellExport StringProperty : public AbstractProperty
{
public:
	/**
	*/
	StringProperty(void);

	/**
	*/
	StringProperty(const String& key, const String& value);

	/**
	*/
	StringProperty(const StringProperty& other);

	/**
	*/
	virtual ~StringProperty(void);

public:
	/**
	*/
	StringProperty& operator=(const StringProperty& r);

	/**
	*/
	const String& getKey(void) const;

	/**
	*/
	String getValue(void) const;

	/**
	*/
	void copy(AbstractProperty* dest) const;

private:
	PropertyReference<String> mReference;
};

} // end namespace cell

#endif // CellPropertyReference_h
